package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.EcologyPoolCommunityServiceRankIncomeConditionConf;
import com.sc.nft.mapper.EcologyPoolCommunityServiceRankIncomeConditionConfMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author 刘国航
 * @since 2024/7/16
 */
@Slf4j
@Repository
public class EcologyPoolCommunityServiceRankIncomeConditionConfDao extends ServiceImpl<EcologyPoolCommunityServiceRankIncomeConditionConfMapper, EcologyPoolCommunityServiceRankIncomeConditionConf> {

    public List<EcologyPoolCommunityServiceRankIncomeConditionConf> getListByConfId(Long confId) {
        LambdaQueryWrapper<EcologyPoolCommunityServiceRankIncomeConditionConf> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(EcologyPoolCommunityServiceRankIncomeConditionConf::getEcologyPoolCommunityServiceRankConfId, confId);
        return baseMapper.selectList(queryWrapper);
    }

    public EcologyPoolCommunityServiceRankIncomeConditionConf getRankConfIdAndIncomeConfigId(Long configId, Long incomeConfigId) {
        LambdaQueryWrapper<EcologyPoolCommunityServiceRankIncomeConditionConf> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(EcologyPoolCommunityServiceRankIncomeConditionConf::getEcologyPoolCommunityServiceRankConfId,configId);
        wrapper.eq(EcologyPoolCommunityServiceRankIncomeConditionConf::getEcologyPoolCommunityServiceRankIncomeConfId,incomeConfigId);
        wrapper.orderByDesc(EcologyPoolCommunityServiceRankIncomeConditionConf::getId);
        wrapper.last("limit 1");
        return getOne(wrapper);
    }
}
